<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Home
 *
 * @author ervinne
 */
class Home extends Controller {

    protected $testPageFieldValidationConditions = [

        'username' => [
            'required' => true,
            'alphanumeric' => true,
            'maxlength' => 20,
            'minlength' => 4
        ],
        'email' => [
            'required' => true,
            'email' => true,
            'maxlength' => 64,
            'minlength' => 6
        ],
        'password' => [
            'required' => true,
            'minlength' => 8
        ],
        'password_retyped' => [
            'match' => 'password'
        ]
    ];

    public function index() {
        $this->load_view('testvalidator');
    }

    public function validate() {

        $errorHandler = new ErrorHandler();
        $parameters = $_POST;

        if (!empty($parameters)) {
            $validator = new Validator($errorHandler);
            $validator->check($parameters, $this->testPageFieldValidationConditions);

            if ($validator->fails()) {
                echo 'errors: <br/>';
                echo '<pre>' . print_r($validator->errors()->all()) . '</pre>';
            }
        }
    }

}
